home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Interfaces&Libraries / Universal / Interfaces / CIncludes / fenv.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-17  |  11.5 KB  |  309 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        fenv.h
  3.  
  4.      Contains:    Floating-Point environment for PowerPC and 68K
  5.  
  6.      Version:    Technology:    MathLib v2
  7.                  Release:    Universal Interfaces 3.2
  8.  
  9.      Copyright:    © 1987-1998 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __FENV__
  18. #define __FENV__
  19.  
  20. #ifndef __CONDITIONALMACROS__
  21. #include <ConditionalMacros.h>
  22. #endif
  23.  
  24.  
  25.  
  26. #if PRAGMA_ONCE
  27. #pragma once
  28. #endif
  29.  
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33.  
  34. #if PRAGMA_IMPORT
  35. #pragma import on
  36. #endif
  37.  
  38. #if PRAGMA_STRUCT_ALIGN
  39.     #pragma options align=mac68k
  40. #elif PRAGMA_STRUCT_PACKPUSH
  41.     #pragma pack(push, 2)
  42. #elif PRAGMA_STRUCT_PACK
  43.     #pragma pack(2)
  44. #endif
  45.  
  46. #if TARGET_OS_MAC
  47. /*
  48.     A collection of functions designed to provide access to the floating
  49.     point environment for numerical programming. It is modeled after
  50.     the floating-point requirements in C9X.
  51.     
  52.     The file <fenv.h> declares many functions in support of numerical
  53.     programming.  It provides a set of environmental controls similar to
  54.     the ones found in <SANE.h>.  Programs that test flags or run under
  55.     non-default modes must do so under the effect of an enabling
  56.     "fenv_access" pragma.
  57. */
  58.  
  59. /********************************************************************************
  60. *                                                                                *
  61. *    fenv_t         is a type for representing the entire floating-point        *
  62. *                     environment in a single object.                              *
  63. *                                                                                *
  64. *     fexcept_t        is a type for representing the floating-point                *
  65. *                     exception flag state collectively.                           *
  66. *                                                                                *
  67. ********************************************************************************/
  68. #if TARGET_CPU_PPC
  69. typedef long                             fenv_t;
  70. typedef long                             fexcept_t;
  71. /*    Definitions of floating-point exception macros                          */
  72.  
  73. enum {
  74.     FE_INEXACT                    = 0x02000000,
  75.     FE_DIVBYZERO                = 0x04000000,
  76.     FE_UNDERFLOW                = 0x08000000,
  77.     FE_OVERFLOW                    = 0x10000000,
  78.     FE_INVALID                    = 0x20000000
  79. };
  80.  
  81.  
  82. /*    Definitions of rounding direction macros                                */
  83.  
  84. enum {
  85.     FE_TONEAREST                = 0x00000000,
  86.     FE_TOWARDZERO                = 0x00000001,
  87.     FE_UPWARD                    = 0x00000002,
  88.     FE_DOWNWARD                    = 0x00000003
  89. };
  90.  
  91. #endif  /* TARGET_CPU_PPC */
  92.  
  93. #if TARGET_CPU_68K
  94. #if TARGET_RT_MAC_68881
  95. typedef long                             fexcept_t;
  96.  
  97. struct fenv_t {
  98.     long                             FPCR;
  99.     long                             FPSR;
  100. };
  101. typedef struct fenv_t                    fenv_t;
  102.  
  103. enum {
  104.     FE_INEXACT                    = 0x00000008,                    /* ((long)(8))   */
  105.     FE_DIVBYZERO                = 0x00000010,                    /* ((long)(16))  */
  106.     FE_UNDERFLOW                = 0x00000020,                    /* ((long)(32))  */
  107.     FE_OVERFLOW                    = 0x00000040,                    /* ((long)(64))  */
  108.     FE_INVALID                    = 0x00000080                    /* ((long)(128)) */
  109. };
  110.  
  111. #else
  112.  
  113. typedef short                             fexcept_t;
  114. typedef short                             fenv_t;
  115.  
  116. enum {
  117.     FE_INVALID                    = 0x0001,                        /* ((short)(1))  */
  118.     FE_UNDERFLOW                = 0x0002,                        /* ((short)(2))  */
  119.     FE_OVERFLOW                    = 0x0004,                        /* ((short)(4))  */
  120.     FE_DIVBYZERO                = 0x0008,                        /* ((short)(8))  */
  121.     FE_INEXACT                    = 0x0010                        /* ((short)(16)) */
  122. };
  123.  
  124. #endif  /* TARGET_RT_MAC_68881 */
  125.  
  126.  
  127. enum {
  128.     FE_TONEAREST                = 0x0000,                        /* ((short)(0))  */
  129.     FE_UPWARD                    = 0x0001,                        /* ((short)(1))  */
  130.     FE_DOWNWARD                    = 0x0002,                        /* ((short)(2))  */
  131.     FE_TOWARDZERO                = 0x0003                        /* ((short)(3))  */
  132. };
  133.  
  134. /*    Definitions of rounding precision macros  (68K only)                    */
  135.  
  136. enum {
  137.     FE_LDBLPREC                    = 0x0000,                        /* ((short)(0))  */
  138.     FE_DBLPREC                    = 0x0001,                        /* ((short)(1))  */
  139.     FE_FLTPREC                    = 0x0002                        /* ((short)(2))  */
  140. };
  141.  
  142. #endif  /* TARGET_CPU_68K */
  143.  
  144. /*    The bitwise OR of all exception macros                                  */
  145.  
  146. #define      FE_ALL_EXCEPT     ( FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID )
  147. /*    Definition of pointer to IEEE default environment object                */
  148. extern fenv_t _FE_DFL_ENV;               /* default environment object        */
  149. #define FE_DFL_ENV &_FE_DFL_ENV          /* pointer to default environment    */
  150.  
  151. /*******************************************************************************
  152. *     The following functions provide access to the exception flags.  The      *
  153. *     "int" input argument can be constructed by bitwise ORs of the exception  *
  154. *     macros: for example: FE_OVERFLOW | FE_INEXACT.                           *
  155. *******************************************************************************/
  156. /*******************************************************************************
  157. *     The function "feclearexcept" clears the supported exceptions represented *
  158. *     by its argument.                                                         *
  159. *******************************************************************************/
  160. EXTERN_API_C( void ) feclearexcept(int excepts);
  161.  
  162.  
  163.  
  164. /*******************************************************************************
  165. *    The function "fegetexcept" stores a representation of the exception       *
  166. *     flags indicated by the argument "excepts" through the pointer argument   *
  167. *     "flagp".                                                                 *
  168. *******************************************************************************/
  169. EXTERN_API_C( void ) fegetexcept(fexcept_t *flagp, int excepts);
  170.  
  171.  
  172.  
  173. /*******************************************************************************
  174. *     The function "feraiseexcept" raises the supported exceptions             *
  175. *     represented by its argument.                                             *
  176. *******************************************************************************/
  177. EXTERN_API_C( void ) feraiseexcept(int excepts);
  178.  
  179.  
  180.  
  181. /*******************************************************************************
  182. *     The function "fesetexcept" sets or clears the exception flags indicated  *
  183. *     by the int argument "excepts" according to the representation in the     *
  184. *     object pointed to by the pointer argument "flagp".  The value of         *
  185. *     "*flagp" must have been set by a previous call to "fegetexcept".         *
  186. *     This function does not raise exceptions; it just sets the state of       *
  187. *     the flags.                                                               *
  188. *******************************************************************************/
  189. EXTERN_API_C( void ) fesetexcept(const fexcept_t *flagp, int excepts);
  190.  
  191.  
  192.  
  193. /*******************************************************************************
  194. *     The function "fetestexcept" determines which of the specified subset of  *
  195. *     the exception flags are currently set.  The argument "excepts" specifies *
  196. *     the exception flags to be queried as a bitwise OR of the exception       *
  197. *     macros.  This function returns the bitwise OR of the exception macros    *
  198. *     corresponding to the currently set exceptions included in "excepts".     *
  199. *******************************************************************************/
  200. EXTERN_API_C( int ) fetestexcept(int excepts);
  201.  
  202.  
  203.  
  204. /*******************************************************************************
  205. *     The following functions provide control of rounding direction modes.     *
  206. *******************************************************************************/
  207. /*******************************************************************************
  208. *     The function "fegetround" returns the value of the rounding direction    *
  209. *     macro which represents the current rounding direction.                   *
  210. *******************************************************************************/
  211. EXTERN_API_C( int ) fegetround(void );
  212.  
  213.  
  214.  
  215. /*******************************************************************************
  216. *     The function "fesetround" establishes the rounding direction represented *
  217. *     by its argument.  It returns nonzero if and only if the argument matches *
  218. *     a rounding direction macro.  If not, the rounding direction is not       *
  219. *     changed.                                                                 *
  220. *******************************************************************************/
  221. EXTERN_API_C( int ) fesetround(int round);
  222.  
  223.  
  224.  
  225. /*******************************************************************************
  226. *    The following functions manage the floating-point environment, exception  *
  227. *    flags and dynamic modes, as one entity.                                   *
  228. *******************************************************************************/
  229. /*******************************************************************************
  230. *     The function "fegetenv" stores the current floating-point environment    *
  231. *     in the object pointed to by its pointer argument "envp".                 *
  232. *******************************************************************************/
  233. EXTERN_API_C( void ) fegetenv(fenv_t *envp);
  234.  
  235.  
  236.  
  237. /*******************************************************************************
  238. *     The function "feholdexcept" saves the current environment in the object  *
  239. *     pointed to by its pointer argument "envp", clears the exception flags,   *
  240. *     and clears floating-point exception enables.  This function supersedes   *
  241. *     the SANE function "procentry", but it does not change the current        *
  242. *     rounding direction mode.                                                 *
  243. *******************************************************************************/
  244. EXTERN_API_C( int ) feholdexcept(fenv_t *envp);
  245.  
  246.  
  247.  
  248. /*******************************************************************************
  249. *     The function "fesetenv" installs the floating-point environment          *
  250. *     environment represented by the object pointed to by its argument         *
  251. *     "envp".  The value of "*envp" must be set by a call to "fegetenv" or     *
  252. *     "feholdexcept", by an implementation-defined macro of type "fenv_t",     *
  253. *     or by the use of the pointer macro FE_DFL_ENV as the argument.           *
  254. *******************************************************************************/
  255. EXTERN_API_C( void ) fesetenv(const fenv_t *envp);
  256.  
  257.  
  258.  
  259. /*******************************************************************************
  260. *     The function "feupdateenv" saves the current exceptions into its         *
  261. *     automatic storage, installs the environment represented through its      *
  262. *     pointer argument "envp", and then re-raises the saved exceptions.        *
  263. *     This function, which supersedes the SANE function "procexit", can be     *
  264. *     used in conjunction with "feholdexcept" to write routines which hide     *
  265. *     spurious exceptions from their callers.                                  *
  266. *******************************************************************************/
  267. EXTERN_API_C( void ) feupdateenv(const fenv_t *envp);
  268.  
  269.  
  270.  
  271. #if TARGET_CPU_68K
  272. /*******************************************************************************
  273. *     The following functions provide control of rounding precision.           *
  274. *     Because the PowerPC does not provide this capability, these functions    *  
  275. *     are available only for the 68K Macintosh.  Rounding precision values     *
  276. *     are defined by the rounding precision macros.  These functions are       *
  277. *     equivalent to the SANE functions getprecision and setprecision.          *
  278. *******************************************************************************/
  279. EXTERN_API_C( int ) fegetprec(void );
  280.  
  281. EXTERN_API_C( int ) fesetprec(int precision);
  282.  
  283. #endif  /* TARGET_CPU_68K */
  284.  
  285. #endif  /* TARGET_OS_MAC */
  286.  
  287.  
  288.  
  289. #if PRAGMA_STRUCT_ALIGN
  290.     #pragma options align=reset
  291. #elif PRAGMA_STRUCT_PACKPUSH
  292.     #pragma pack(pop)
  293. #elif PRAGMA_STRUCT_PACK
  294.     #pragma pack()
  295. #endif
  296.  
  297. #ifdef PRAGMA_IMPORT_OFF
  298. #pragma import off
  299. #elif PRAGMA_IMPORT
  300. #pragma import reset
  301. #endif
  302.  
  303. #ifdef __cplusplus
  304. }
  305. #endif
  306.  
  307. #endif /* __FENV__ */
  308.  
  309.